home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / SINE.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  71 lines

  1.  
  2. /***********************************************************
  3.  *               The TULSA IBM C BOARD                     *
  4.  *                   918-664-8737                          *
  5.  *             300/1200 XMODEM, 24 Hours                   *
  6.  **********************************************************/
  7.  
  8.  
  9. #include "math.h"
  10. #include "errno.h"
  11.  
  12. double cos(x)
  13. double x;
  14. {
  15.         double sincos();
  16.  
  17.         return sincos(x, fabs(x) + 1.57079632679489661923, 0);
  18. }
  19.  
  20. double sin(x)
  21. double x;
  22. {
  23.         double sincos();
  24.  
  25.         if (x < 0.0)
  26.                 return sincos(x,-x,1);
  27.         else
  28.                 return sincos(x,x,0);
  29. }
  30.  
  31. #define R1 -0.16666666666666665052e+00
  32. #define R2 +0.83333333333331650314e-02
  33. #define R3 -0.19841269841201840457e-03
  34. #define R4 +0.27557319210152756119e-05
  35. #define R5 -0.25052106798274584544e-07
  36. #define R6 +0.16058936490371589114e-09
  37. #define R7 -0.76429178068910467734e-12
  38. #define R8 +0.27204790957888846175e-14
  39.  
  40. #define YMAX 6.7465e09
  41.  
  42. static double sincos(x,y,sgn)
  43. double x,y;
  44. {
  45.         double f, xn, r, g;
  46.         extern int errno;
  47.  
  48.         if (y >= YMAX) {
  49.                 errno = ERANGE;
  50.                 return 0.0;
  51.         }
  52.         if (modf(y * 0.31830988618379067154, &xn) >= 0.5)
  53.                 ++xn;
  54.         if ((int)xn & 1)
  55.                 sgn = !sgn;
  56.         if (fabs(x) != y)
  57.                 xn -= 0.5;
  58.         g = modf(fabs(x), &x);          /* break into fraction and integer parts */
  59.         f = ((x - xn*3.1416015625) + g) + xn*8.9089102067615373566e-6;
  60.         if (fabs(f) > 2.3283e-10) {
  61.                 g = f*f;
  62.                 r = (((((((R8*g R7)*g R6)*g R5)*g
  63.                                 R4)*g R3)*g R2)*g R1)*g;
  64.                 f += f*r;
  65.         }
  66.         if (sgn)
  67.                 f = -f;
  68.         return f;
  69. }
  70.  
  71.